package xyz.ylx.proxy.methodproxy;

import org.springframework.cglib.core.Signature;

public class Main {

    public static void main(String[] args) {
        testTargetFastClass();

        testProxyFastClass();
    }

    private static void testTargetFastClass() {
        TargetFastClass fastClass = new TargetFastClass();
        int index = fastClass.getIndex(new Signature("save", "()V"));
        System.out.println(index);
        fastClass.invoke(index, new Target(), new Object[0]);

        index = fastClass.getIndex(new Signature("save", "(I)V"));
        System.out.println(index);
        fastClass.invoke(index, new Target(), new Object[]{100});

        index = fastClass.getIndex(new Signature("save", "(L)V"));
        System.out.println(index);
        fastClass.invoke(index, new Target(), new Object[]{100L});
    }

    private static void testProxyFastClass() {
        ProxyFastClass fastClass = new ProxyFastClass();
        int index = fastClass.getIndex(new Signature("saveSuper", "()V"));
        System.out.println(index);
        fastClass.invoke(index, new Proxy(), new Object[0]);

        index = fastClass.getIndex(new Signature("saveSuper", "(I)V"));
        System.out.println(index);
        fastClass.invoke(index, new Proxy(), new Object[]{100});

        index = fastClass.getIndex(new Signature("saveSuper", "(L)V"));
        System.out.println(index);
        fastClass.invoke(index, new Proxy(), new Object[]{100L});
    }
}
